home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 50
/
Volume 50 - JOGO DISK .iso
/
Games
/
lightsout.swf
/
scripts
/
frame_2
/
DoAction.as
Wrap
Text File
|
2007-10-01
|
11KB
|
395 lines
function init()
{
music_sound = new Sound();
music_sound.attachSound("music");
light_sound = new Sound();
light_sound.attachSound("light_sound");
if(_global.music == undefined || _global.music == "off")
{
music_sound.start(0,9999999);
_global.music = "on";
}
music_sound.setVolume(35);
saveFile = SharedObject.getLocal("Lights_Out_3D");
generateBackground();
game = {active:false,tileW:50,currentLayer:2,currentTile:null,currentMap:1,currentScore:0,totalScore:0,Mode:"makeCustom",totalMoves:0,overallMoves:0};
loadGame();
saveGame();
}
function generateBackground()
{
d = 0;
xp = 10;
yp = 10;
_root.attachMovie("empty","backgroundTiles",1);
y = 0;
while(y < 4)
{
x = 0;
while(x < 4)
{
name = "t_" + y + "_" + x;
backgroundTiles.attachMovie("menuTile",name,d);
d++;
backgroundTiles[name]._x = xp;
backgroundTiles[name]._y = yp;
backgroundTiles[name].gotoAndStop("off");
xp += 110;
x++;
}
yp += 110;
xp = 10;
y++;
}
backgroundTiles._alpha = 15;
i = 0;
while(i < 4)
{
y = Math.floor(Math.random() * 7);
x = Math.floor(Math.random() * 9);
changeLights(x,y);
i++;
}
wait = setInterval(triggerLights,1000);
generateMenu();
}
function triggerLights()
{
y = Math.floor(Math.random() * 4);
x = Math.floor(Math.random() * 4);
changeLights(x,y);
}
function changeLights(x, y)
{
tile1 = backgroundTiles["t_" + y + "_" + x];
tile2 = backgroundTiles["t_" + (y + 1) + "_" + x];
tile3 = backgroundTiles["t_" + (y - 1) + "_" + x];
tile4 = backgroundTiles["t_" + y + "_" + (x + 1)];
tile5 = backgroundTiles["t_" + y + "_" + (x - 1)];
i = 1;
while(i <= 5)
{
tile = _root["tile" + i];
if(tile != undefined)
{
frame = tile._currentframe;
if(frame == 1)
{
tile.gotoAndStop("on");
}
else
{
tile.gotoAndStop("off");
}
}
i++;
}
}
function generateMenu()
{
buttons = ["New Game","Continue","Random","Play Custom","Make Custom","How To Play","Highscores","Credits"];
_root.attachMovie("empty","menuClips",2);
menuClips.attachMovie("tittle","tittle",200);
menuClips.tittle._x = Stage.width / 2;
menuClips.tittle._y = menuClips.tittle._height / 2 + 50;
i = 0;
while(i < buttons.length)
{
name = buttons[i];
menuClips.attachMovie("menuButton",name,i);
menuClips[name]._x = Stage.width / 2;
menuClips[name]._y = i * 30 + 200;
menuClips[name].t.text = buttons[i];
i++;
}
_root.attachMovie("error_message","errorMessage",3);
errorMessage._x = Stage.width / 2;
errorMessage._y = Stage.height - 20;
}
function saveGame()
{
saveFile.data.currentMap = game.currentMap;
saveFile.data.totalScore = game.totalScore;
}
function loadGame()
{
errorMessage.display_txt.text = "*Looking for saved game*";
if(saveFile.data.currentMap != undefined)
{
errorMessage.display_txt.text = "*Loading saved game*";
game.currentMap = saveFile.data.currentMap;
game.totalScore = saveFile.data.totalScore;
i = 0;
while(i < 5)
{
errorMessage.display_txt.text = "*Looking for custom map data*";
if(saveFile.data["customMapName" + i] != undefined)
{
_root["customMap" + i] = new Object();
_root["customMap" + i].name = saveFile.data["customMapName" + i];
_root["customMap" + i].map = saveFile.data["customMapArray" + i];
errorMessage.display_txt.text = "*Loading Custom Map : " + _root["customMap" + i].name + "*";
errorMessage.play();
}
i++;
}
errorMessage.display_txt.text = "*Game data loaded successfully*";
menuClips.NewGame.toString.text = "Continue";
loaded = true;
errorMessage.play();
menuClips._y = 0;
}
else
{
errorMessage.display_txt.text = "*No saved game found*";
errorMessage.play();
menuClips._y = 0;
}
}
function setupBoard(quitButton, infoPannel, resetButton, lvl)
{
if(quitButton != undefined)
{
_root.attachMovie("menuButton","Quit",200);
Quit.t.text = "Quit";
Quit._x = Quit._width / 2 + 10;
Quit._y = Quit._height / 2 + 10;
}
if(resetButton != undefined)
{
_root.attachMovie("menuButton","Reset",201);
Reset.t.text = "Reset Level";
Reset._x = Reset._width / 2 + 10;
Reset._y = Reset._height / 2 + 35;
}
if(infoPannel != undefined)
{
_root.attachMovie("info","info",202);
info._x = Stage.width - 10;
info._y = 10;
if(game.Mode == "normal")
{
info.lvl.text = game.currentMap;
info.score.text = game.totalScore;
info.moves.text = game.totalMoves;
}
else
{
info.lvl.text = lvl;
info.score.text = "n/a";
info.moves.text = game.totalMoves;
}
}
}
function loadScores()
{
var _loc6_ = "http://localhost/gameTest2/lightOut_highscores.php?task=read";
var _loc5_ = new LoadVars();
_loc5_.onLoad = function(success)
{
if(success)
{
scoreArray = this.scores;
scoreArray = scoreArray.split("|");
var _loc2_ = new Array();
i = 0;
while(i < scoreArray.length - 1)
{
_loc2_.push({user:scoreArray[i],score:scoreArray[i + 1]});
i += 2;
}
_loc2_.sort(compareNumbers);
i = 0;
while(i < _loc2_.length)
{
i++;
}
displayScores(_loc2_);
}
};
_loc5_.load(_loc6_);
}
function compareNumbers(a, b)
{
res = (Number(a.score) > Number(b.score)) - (Number(a.score) < Number(b.score));
return res;
}
function displayScores(scores)
{
p = 1;
i = scores.length - 1;
while(p < 6)
{
scores_page["name" + p].text = scores[i].user;
scores_page["score" + p].text = scores[i].score;
p++;
i--;
}
}
stop();
loaded = false;
init();
menuClips["New Game"].btn.onRelease = function()
{
removeMovieClip(menuClips);
game.currentMap = 1;
game.currentScore = 0;
game.totalScore = 0;
game.totalMoves = 0;
game.Mode = "normal";
gotoAndStop("game");
setupBoard(1,1,1);
};
menuClips.Continue.btn.onRelease = function()
{
removeMovieClip(menuClips);
game.Mode = "normal";
setupBoard(1,1,1);
gotoAndStop("game");
};
menuClips.Random.btn.onRelease = function()
{
removeMovieClip(menuClips);
setupBoard(1,1,1);
game.Mode = "random";
gotoAndStop("game");
};
menuClips["How To Play"].btn.onRelease = function()
{
menuClips._y = 500;
attachMovie("help_page","help_page",4);
help_page._x = Stage.width / 2;
help_page._y = Stage.height / 2;
help_page.btn.onRelease = function()
{
removeMovieClip(help_page);
menuClips._y = 0;
};
};
menuClips.Highscores.btn.onRelease = function()
{
menuClips._y = 500;
attachMovie("scores_page","scores_page",4);
scores_page._x = Stage.width / 2;
scores_page._y = Stage.height / 2;
loadScores();
scores_page.btn.onRelease = function()
{
removeMovieClip(scores_page);
menuClips._y = 0;
};
};
menuClips.Credits.btn.onRelease = function()
{
menuClips._y = 500;
attachMovie("credits_page","credits_page",4);
credits_page._x = Stage.width / 2;
credits_page._y = Stage.height / 2;
credits_page.btn.onRelease = function()
{
removeMovieClip(credits_page);
menuClips._y = 0;
};
};
menuClips["Play Custom"].btn.onRelease = function()
{
menuClips._y = 500;
_root.attachMovie("empty","customs",5);
i = 1;
while(i < 7)
{
if(i != 6)
{
name = _root["customMap" + i].name;
customs.attachMovie("menuButton","loadCustom" + i,i);
customs["loadCustom" + i]._x = Stage.width / 2;
customs["loadCustom" + i]._y = i * 40 + 160;
customs["loadCustom" + i].t.text = name;
}
else
{
customs.attachMovie("menuButton","Back",i);
customs.Back.t.text = "Back";
customs.Back._x = Stage.width / 2;
customs.Back._y = i * 40 + 160;
}
i++;
}
customs.Back.btn.onRelease = function()
{
removeMovieClip(customs);
menuClips._y = 0;
};
customs.loadCustom1.btn.onRelease = function()
{
if(customMap1.name != undefined)
{
removeMovieClip(customs);
removeMovieClip(menuClips);
game.currentMap = customMap1.map;
game.Mode = "playCustom";
gotoAndStop("game");
setupBoard(1,1,1,customMap1.name);
}
};
customs.loadCustom2.btn.onRelease = function()
{
if(customMap2.name != undefined)
{
removeMovieClip(customs);
removeMovieClip(menuClips);
game.currentMap = customMap2.map;
game.Mode = "playCustom";
gotoAndStop("game");
setupBoard(1,1,1,customMap2.name);
}
};
customs.loadCustom3.btn.onRelease = function()
{
if(customMap3.name != undefined)
{
removeMovieClip(customs);
removeMovieClip(menuClips);
game.currentMap = customMap3.map;
game.Mode = "playCustom";
gotoAndStop("game");
setupBoard(1,1,1,customMap3.name);
}
};
customs.loadCustom4.btn.onRelease = function()
{
if(customMap4.name != undefined)
{
removeMovieClip(customs);
removeMovieClip(menuClips);
game.currentMap = customMap4.map;
game.Mode = "playCustom";
gotoAndStop("game");
setupBoard(1,1,1,customMap4.name);
}
};
customs.loadCustom5.btn.onRelease = function()
{
if(customMap5.name != undefined)
{
removeMovieClip(customs);
removeMovieClip(menuClips);
game.currentMap = customMap5.map;
game.Mode = "playCustom";
gotoAndStop("game");
setupBoard(1,1,1,customMap5.name);
}
};
};
menuClips["Make Custom"].btn.onRelease = function()
{
setupBoard(1);
game.Mode = "makeCustom";
_root.attachMovie("menuButton","saveCustom",10);
saveCustom.t.text = "Save Level";
saveCustom._x = Stage.width / 2;
saveCustom._y = Stage.height - 60;
removeMovieClip(menuClips);
gotoAndStop("game");
};